package method.method1202;

import java.util.Random;
import java.util.Scanner;

//猜随机数字
public class guess01 {
    public static void main(String[] args) {
        Random r=new Random();
        Scanner sc=new Scanner(System.in);
        System.out.println("请在1~100之间输入一个数字：");
        int num=r.nextInt(100)+1;
        int a=sc.nextInt();
        int max=100;
        int min=1;
        while(true){
            if (a==num){
                System.out.println("猜对了");
                break;
            }else if (a>num&&a<=100){
                max=a;
                System.out.println(min+"~"+max);
                a=sc.nextInt();
            }else if(a<num&&a>=1){
                min=a;
                System.out.println(min+"~"+max);
                a=sc.nextInt();
            }else{
                System.out.println("输入有误，请重新输入：");
                a=sc.nextInt();
            }
        }
    }
}
